package com.tuozixuan.factory.simple3;

import java.util.HashMap;
import java.util.Map;

/**
 * 简单工厂模式-使用newInstance方法进行类注册的简单工厂模式<br/>
 * 将要注册的每种对象实例添加到map对象中，每个产品类都能够创建自己的实例<br/>
 * 
 * @author tuozixuan
 *
 */
public class VehicleFactory {
	
	private Map<String, Vehicle> registeredProducts = new HashMap<>();

	public enum VehicleType {
		Bike, Car, Truck;
	}
	
	public void registerVehicle(String vehicleId, Vehicle vehicle) {
		registeredProducts.put(vehicleId, vehicle);
	}
	
	public Vehicle createVehicle(String vehicleId) throws InstantiationException, IllegalAccessException {
		return registeredProducts.get(vehicleId).newInstance();
	}
}
